/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

/**
 *
 * @author Administrator
 */
public class Transform {
    public static String transNumToCN(String text){
        String [] cnNum = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        String [] cnCount = {"万","仟", "佰","拾"};
        String cnNumber = null;
        double n = 0.00;
        try{
        n = Double.parseDouble(text);
        }catch(NumberFormatException ee){cnNumber = "非法数字!"; return cnNumber;}
        if( n>=0.00 && n<100000.00){
            double m = n;
            try{
                m = Double.parseDouble(text);
            }catch(NumberFormatException ee){cnNumber = "系统错误!"; return cnNumber;}
            int m1 = (int) ((m*100)%100);
            int m2 = (int) Math.floor(m);
            int num [] = new int [7];
            num[0] = m2/10000;
            num[1] = (m2%10000)/1000;
            num[2] = (m2%1000)/100;
            num[3] = (m2%100)/10;
            num[4] = m2%10;
            num[5] = m1/10;
            num[6] = m1%10;
            int index = 0;
            for(int i = 0;i<7;i++) {
            	if(num[i]!=0) {
            		index = i;
            		break;
            	}
            }
            System.out.println(index);
            if(index == 0)
            	cnNumber = (cnNum[num[0]]+cnCount[0]+cnNum[num[1]]+cnCount[1]
                        +cnNum[num[2]]+cnCount[2]+cnNum[num[3]]+cnCount[3]+cnNum[num
                        [4]]+"元"+cnNum[num[5]]+"角"+cnNum[num[6]]+"分");
            if(index == 1)
            	cnNumber = (cnNum[num[1]]+cnCount[1]+cnNum[num[2]]+cnCount[2]+cnNum[
            	        num[3]]+cnCount[3]+cnNum[num[4]]+"元"+cnNum[num[5]]+"角"+cnNum
                        [num[6]]+"分");
            if(index == 2)
            	cnNumber = (cnNum[num[2]]+cnCount[2]+cnNum[num[3]]+cnCount[3]+cnNum[
            	        num[4]]+"元"+cnNum[num[5]]+"角"+cnNum[num[6]]+"分");
            if(index == 3)
            	cnNumber = (cnNum[num[3]]+cnCount[3]+cnNum[num[4]]+"元"+cnNum[num[5]]
            			+"角"+cnNum[num[6]]+"分");
            if(index == 4)
            	cnNumber = (cnNum[num[4]]+"元"+cnNum[num[5]]+"角"+cnNum[num[6]]+"分");
            if(index == 5)
            	cnNumber = (cnNum[num[5]]+"角"+cnNum[num[6]]+"分");
            if(index == 6)
            	cnNumber = (cnNum[num[6]]+"分");
        }
        else if(n == 100000.00){
            cnNumber = "拾万元";
        }
        else {
            cnNumber = "超出范围!";
        }
        return cnNumber;
    }  
}
